package com.zy.cloud.controller;

import com.zy.cloud.service.UserHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName: UserHystrixController
 * @Description: #TODO
 * @Author: yanzy
 * @Date: 2021/3/3 21:40
 */
@RestController
@Slf4j
public class UserHystrixController {

    @Resource
    private UserHystrixService userHystrixService;

    @Value("server.port")
    private String serverPort;

    @GetMapping("/hystrix/user/ok/{id}")
    public String reqOk(@PathVariable("id") Integer id) {
        String s = userHystrixService.reqOk(id);
        log.info("响应信息: {} - {}", serverPort, s);
        return s;
    }


    @GetMapping("/hystrix/user/timeout/{id}")
    public String reqTimeOut(@PathVariable("id") Integer id) {
        String s = userHystrixService.reqTimeOut(id);
        log.info("响应信息: {} - {}", serverPort, s);
        return s;
    }

    // ===== 服务熔断
    @GetMapping("/hystrix/user/open/{id}")
    public String openCircuitBreaker(@PathVariable("id") Integer id) {

        return userHystrixService.openCircuitBreaker(id);
    }
}
